﻿using LxBasic;
using System.Runtime.CompilerServices;

namespace LxCore
{
    public class StateArray<T> where T : IEquatable<T>
    {
        public StateArray(int length) { SetLength(length); }
        protected T[] States;
        public T this[int i]
        {
            get { return States[i]; }
            set
            {
                if (!value.Equals(States[i]))
                {
                    States[i] = value;
                    IsChanged = true;
                }
            }
        }
        public int Length => States.Length;
        public bool IsChanged { get; set; } = true;
        public void SetLength(int length)
        {
            bool c = CheckCreator.ArrayStrict(ref States, length);
            if (c) { IsChanged = true; }
        }
        //public void SetState(int id, T state)
        //{
        //    if (!state.Equals(States[id]))
        //    {
        //        States[id] = state;
        //        IsChanged = true;
        //    }
        //}
    }
}
